import router from "@/router/index"
import store from "@/store"
import { Loading } from 'element-ui';

router.beforeEach(async(to, from, next) => {
    
    const whiteList = ['/login', '/register']
    
    const loading = Loading.service({ fullscreen: true })
    setTimeout(() => {
        loading.close();
        next()
    }, 250)
    
    if (whiteList.indexOf(to.path) !== -1) {
        next()
    } else {
        const id = sessionStorage.getItem('id')
        if (id === undefined || id === null){
            next('/login')
        }else {
            if (store.getters.id===0){
                await store.dispatch('user/getInfo')
            }
            next()
        }
    }
})

router.afterEach((to, from) => {
    document.title = to.meta.title
})
